package com.example.a79273.shandianban.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a79273.shandianban.R;
import com.example.a79273.shandianban.config.NetConfigYouRen;
import com.example.a79273.shandianban.model.YouLiaoContent;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 79273 on 2016/8/31.
 */
public class YouLiaoListAdapter extends BaseAdapter {
    private List<YouLiaoContent.DataBean.ListBean> mData;
    private LayoutInflater inflater;
    private Picasso picasso;

    public YouLiaoListAdapter(Context context, List<YouLiaoContent.DataBean.ListBean> data) {
        mData = data;
        inflater = LayoutInflater.from(context);
        picasso = Picasso.with(context);
    }

    @Override
    public int getCount() {
        return mData == null ? 0 : mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_youliaocontent, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        YouLiaoContent.DataBean.ListBean bean = mData.get(position);
        picasso.load(NetConfigYouRen.ROOT_URL + bean.getScr()).into(holder.imageView);
        holder.textView.setText(bean.getTitle());
        return convertView;
    }

    public static class ViewHolder {
        private ImageView imageView;
        private TextView textView;

        public ViewHolder(View view) {
            imageView = (ImageView) view.findViewById(R.id.iv_youLiaoContent_pic);
            textView = (TextView) view.findViewById(R.id.tv_youLiaoContent_title);
        }
    }
}
